package com.ds.common.org.expression.org;

import java.util.Stack;

import com.ds.common.expression.ParseException;
import com.ds.common.expression.function.Function;
import com.ds.org.Org;

 /** 
 * <p>Title: JDSORG组织机构中间件</p>
 * <p>Description:
 * 3.2.23.	判断两个组织是否是同一个组织<br>
    Boolean SameOrg(Org org1, Org org2)<br>
    参数：org1 - 比较两个组织中的一个<br>
          org2 - 比较得两个组织中的另一个<br>
    返回值：如果两个组织是同一个组织（组织ID相同）返回True，否则返回False。<br>
 </p>
 * <p>Copyright: jds Copyright (c) 2003-2008</p>
 * <p>Company: www.justdos.net</p>
 * @author lxl
 * @version 2.0
 */
public class SameOrg extends Function {
	public SameOrg() {
		numberOfParameters = 2;
	}
	public void run(Stack stack) throws ParseException
	{
		checkStack(stack); // check the stack
		Object param2 = stack.pop();
		Object param1 = stack.pop();
		stack.push(perform(param1, param2));
	}

	protected Boolean perform(Object param1, Object param2) throws ParseException {
		if (param1 == null || param2 == null) {
			return Boolean.FALSE;
		}
		if (param1 instanceof Org && param2 instanceof Org) {
		    Org org1 = (Org)param1;
		    Org org2 = (Org)param2;
		    if(org1.getOrgId() == null) {
		        return Boolean.FALSE;
		    }
			return Boolean.valueOf(org1.getOrgId().equalsIgnoreCase(org2.getOrgId()));
		}
		throw new ParseException("Invalid parameter type in:" + this.getClass().getName() + ", param1 is " + param1.getClass().getName() + ", param2 is " + param2.getClass().getName());
	}
}
